package top.ysh.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.ysh.provider.domain.Goods;
import top.ysh.provider.service.GoodsService;

import javax.lang.model.element.VariableElement;

/**
 * Goods Controller 服务提供方
 */
@RequestMapping("/goods")
@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Value("${server.port}")
    private int port;

    @GetMapping("/findOne/{id}")
    public Goods findOneById(@PathVariable("id") int id){
        Goods goods = goodsService.findOneById(id);
        goods.setTitle(goods.getTitle()+":"+port);  // 将端口号，设置到标题上
        return goods;
    }
}
